/*
 * Inspiration from http://www.antonioshome.net/kitchen/swingnbrcp/swingnbrcp-nodes1.php,
 * http://kenai.com/projects/swingnbrcp/sources/source/content/NBTWEETING/src/net/antonioshome/nbtweeting/nodes/TweetNode.java?rev=2
 */
package org.tintuna.cca.node;

import java.beans.PropertyEditor;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.util.lookup.ProxyLookup;
import org.tintuna.cca.ability.ReloadableNode;
import org.tintuna.cca.data.Spreadsheet;
import org.tintuna.cca.data.Spreadsheet;

/**
 *
 * @author bsmith
 */
public class SpreadsheetNode extends AbstractNode {

    private Spreadsheet spreadsheet;
    private InstanceContent instanceContent;

    public SpreadsheetNode(Spreadsheet spreadsheet) {
        this(spreadsheet, new InstanceContent());
    }

    public SpreadsheetNode(Spreadsheet spreadsheet, InstanceContent instanceContent) {
        super(Children.create(new SpreadsheetNodeChildFactory(spreadsheet), true), new ProxyLookup(spreadsheet.getLookup(), new AbstractLookup(instanceContent)));
        this.spreadsheet = spreadsheet;
        this.instanceContent = instanceContent;
        this.instanceContent.add(new ReloadableNode() {

            public void reloadChildren() throws Exception {
                // To reload this node just set a new set of children
                // using a SpreadsheetNodeChildFactory object, that retrieves
                // children asynchronously
                setChildren(
                        Children.create(
                        new SpreadsheetNodeChildFactory(SpreadsheetNode.this.spreadsheet),
                        true));
            }
        });
        // Add abilities to the  node in this instanceContent
        // this.instanceContent.add( new WhateverAbility() );
    }

    @Override
    public String getDisplayName() {
        return spreadsheet.getName();
    }
}
